package com.example.pattern.singleton;

/**
 * 饿汉模式
 * 饿汉式 是在 jvm 加载类的时候就初始化好了
 *
 */
public class HungrySingletonTest {

    public static void main(String[] args) {
        HungrySingleton singleton = HungrySingleton.getInstance();
        HungrySingleton singleton1 = HungrySingleton.getInstance();
        System.out.println(singleton == singleton1);
    }
}

class HungrySingleton{

    private static HungrySingleton instance = new HungrySingleton();
    private HungrySingleton(){}

    public static HungrySingleton getInstance() {
        return instance;
    }
}
